package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Square;
import com.ruoyi.system.service.ISquareService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 广场发布的页面模块Controller
 * 
 * @author ruoyi
 * @date 2022-12-08
 */
@Controller
@RequestMapping("/system/square")
public class SquareController extends BaseController
{
    private String prefix = "system/square";

    @Autowired
    private ISquareService squareService;

    @RequiresPermissions("system:square:view")
    @GetMapping()
    public String square()
    {
        return prefix + "/square";
    }

    /**
     * 查询广场发布的页面模块列表
     */
    @RequiresPermissions("system:square:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Square square)
    {
        startPage();
        List<Square> list = squareService.selectSquareList(square);
        return getDataTable(list);
    }

    /**
     * 导出广场发布的页面模块列表
     */
    @RequiresPermissions("system:square:export")
    @Log(title = "广场发布的页面模块", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Square square)
    {
        List<Square> list = squareService.selectSquareList(square);
        ExcelUtil<Square> util = new ExcelUtil<Square>(Square.class);
        return util.exportExcel(list, "广场发布的页面模块数据");
    }

    /**
     * 新增广场发布的页面模块
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存广场发布的页面模块
     */
    @RequiresPermissions("system:square:add")
    @Log(title = "广场发布的页面模块", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Square square)
    {
        return toAjax(squareService.insertSquare(square));
    }

    /**
     * 修改广场发布的页面模块
     */
    @RequiresPermissions("system:square:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Square square = squareService.selectSquareById(id);
        mmap.put("square", square);
        return prefix + "/edit";
    }

    /**
     * 修改保存广场发布的页面模块
     */
    @RequiresPermissions("system:square:edit")
    @Log(title = "广场发布的页面模块", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Square square)
    {
        return toAjax(squareService.updateSquare(square));
    }

    /**
     * 删除广场发布的页面模块
     */
    @RequiresPermissions("system:square:remove")
    @Log(title = "广场发布的页面模块", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(squareService.deleteSquareByIds(ids));
    }
}
